package com.aw.guiguzi.module.manager.transaction.adapter

import com.aw.baselib.bean.CommonImgItemBean
import com.aw.baselib.util.AwDataUtil
import com.aw.baselib.util.AwImgUtil
import com.aw.guiguzi.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

class ManagerTransactionImgAdapter :
    BaseQuickAdapter<CommonImgItemBean, BaseViewHolder>(R.layout.adapter_manager_transaction_img) {
    private var mList: MutableList<CommonImgItemBean>? = ArrayList()

    init {
        if (mList == null) {
            mList = ArrayList()
        }
    }

    override fun convert(helper: BaseViewHolder, bean: CommonImgItemBean) {
//        TextView tv_name = helper.getView(R.id.tv_name);
//        if(!AwDataUtil.isEmpty(bean.getDescribe()) && bean.getDescribe().contains("-")) {
//            tv_name.setText(matcherSearchText(mContext.getResources().getColor(R.color.teal_700), bean.getDescribe(), bean.getDescribe().split("-")[0], false));
//        } else {
//            helper.setText(R.id.tv_name, bean.getDescribe());
//        }
        helper.setText(R.id.tv_name, bean.describe)
        AwImgUtil.setImg(
            mContext,
            helper.getView(R.id.iv_img),
            if (AwDataUtil.isEmpty(bean.imgPath)) bean.resId else bean.imgPath
        )
    }

    fun addAllData(dataList: MutableList<CommonImgItemBean>?) {
        mList = dataList
        setNewData(mList)
        notifyDataSetChanged()
    }

    fun clearData() {
        if (mList != null) {
            val startPosition = 0 //hasHeader is 1
            val preSize = mList!!.size
            if (preSize > 0) {
                mList!!.clear()
                notifyItemRangeRemoved(startPosition, preSize)
            }
        }
    }
}